import { BaseWindow } from "../../../component/window/BaseWindow";
import { PetMeetEventName } from "./info/PetMeetEventName";
import { ObjCreate } from "../common/ObjCreate";
import { TilePanel } from "../equipment/TilePanel";
import { PetMeetPetSelectRender } from "./PetMeetPetSelectRender";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { GButton } from "../../../../com/mui/controls/GButton";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { EPetStatus } from "../../../../Message/Game/EPetStatus";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
//class PetMeetSelectPetWindow
    
    export  class PetMeetSelectPetWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this.setSize(230, 215);
            this.title = "宠物列表";
            this.titleHeight = 30;
            this.addEventListener(PetMeetEventName.SelectedPet, this.onSelectedPetHandler);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(20, 42, 170, 125, this);
            this._petListPanel = new TilePanel();
            this._petListPanel.styleName = "GScrollPane";
            this._petListPanel.setSize(185, 120);
            this._petListPanel.columnWidth = 175;
            this._petListPanel.rowHeight = 25;
            this._petListPanel.x = 25;
            this._petListPanel.y = 47;
            this._petListPanel.setStyle("cellRenderer", PetMeetPetSelectRender);
            this._petListPanel.scrollPolicy = ScrollPolicy.ON;
            this._petListPanel.drawNow();
            this.addChild(this._petListPanel);
            this._okBtn = new GButton();
            this._okBtn.label = "确  定";
            this._okBtn.styleName = "Button";
            this._okBtn.setSize(46, 27);
            this._okBtn.move(60, 175);
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkBtnClickHandler);
            this.addChild(this._okBtn);
            this._cancelBtn = new GButton();
            this._cancelBtn.label = "取  消";
            this._cancelBtn.styleName = "Button";
            this._cancelBtn.setSize(46, 27);
            this._cancelBtn.move(120, 175);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            this.addChild(this._cancelBtn);
            return;
        }

        public updateDataProvider(arg1: Array<any>): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=new DataProvider();
            if (arg1 && arg1.length > 0) 
            {
                loc3 = 0;
                while (loc3 < arg1.length) 
                {
                    loc2 = arg1[loc3] as SPetInfo;
                    if ((loc2.status == EPetStatus._EPetRest || loc2.status == EPetStatus._EPetEquip) && !loc2.isBorrow) 
                    {
                        loc1.addItem(loc2);
                    }
                    ++loc3;
                }
            }
            this._petListPanel.dataProvider = loc1;
            PetMeetSelectPetWindow._petInfo = null;
            return;
        }

        /* internal  */onOkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (PetMeetSelectPetWindow._petInfo) 
            {
                Dispatcher.dispatchEvent(new DataEvent(PetMeetEventName.ConfirmSelectedPet, PetMeetSelectPetWindow._petInfo));
            }
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */onSelectedPetHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SPetInfo;
            this.petInfo = loc1;
            return;
        }

        public get petInfo(): SPetInfo
        {
            return PetMeetSelectPetWindow._petInfo;
        }

        public set petInfo(arg1: SPetInfo)
        {
            PetMeetSelectPetWindow._petInfo = arg1;
            return;
        }

        /* internal */ /* var */_petListPanel: TilePanel;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ static /* var */_petInfo: SPetInfo;
    }
